<?php
namespace app\index\controller;

use think\facade\Request;

class Api{
    public function web(){

        $content = Request::param('content');
        $v= Request::param('v');
        //去除空格，转换成键值
        $explode = explode(' ',$content);
        //键值唯一
        $unique = array_unique($explode);
        //重排数组
        $values = array_values($unique);

        //改进端口,根据版本号来设置
        if($v==1){

            $date = [
                'status' => 404,
                'message' => '这个号没了',
                'date' => $values
            ];
            return json($date);
        } else if($v == 2){
            $arr = [];
            $values = array_values($explode);
            foreach($values as $row){
                if(empty($arr[$row])){
                    $arr[$row] = 0;
                }
                $arr[$row]++;
            }
            $date = [
                'status' => 403,
                'message' => '你没有权限',
                'date' => $arr
            ];

            return json($date);
        }

    }
    //返回一个长度
    public function length(){
        $length = Request::param('v');
        //去掉空格,返回一个数组
        $explode = explode(' ',$length);
        $arr = 0;

        foreach($explode as $row){
            $arr += strlen($row);
        }
        $date = [
            'status' => 200,
            'message' => 'ok没问题',
            'date' => '长度为：'.$arr
        ];
        return json($date);
    }
}